package org.example.blogserver.blog.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.example.blogpojo.blog.domain.Param;
import org.example.blogserver.blog.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController//rc
@RequestMapping("/param")
public class ParamController {
    @Autowired
    private ParamService paramService;

    @GetMapping("/map")
    @Operation (summary = "查所有", description = "查所有")
    public Map<String, String> map() {
        List<Param> list = paramService.findAll();
        //Map<String,String> map = new HashMap<>();
        Map<String, String> map = list.stream().collect(Collectors.toMap(Param::getParamKey, Param::getParamValue));
        //for (Param param : list) {
        //    map.put(param.getParamKey(), param.getParamValue());
        //}
        return map;
    }
}
